package com.jintian.smart.base.expression.fn;

import com.jintian.smart.base.api.system.provider.IEmployeeProvider;
import com.jintian.smart.kernel.common.context.ContextHolder;
import com.jintian.smart.kernel.core.annotation.beetl.BeetlFunction;
import org.apache.dubbo.config.annotation.DubboReference;
import org.beetl.core.Context;
import org.beetl.core.Function;

@BeetlFunction(code = "hasRole")
public class HasRoleFunction implements Function {
    @DubboReference(check = false)
    private IEmployeeProvider employeeProvider;

    @Override
    public Object call(Object[] paras, Context ctx) {
        String userId = (String) paras[0];
        String roleCode = (String) paras[1];
        if (userId == null) {
            userId = ContextHolder.getUserId();
        }
        return employeeProvider.userExistsRoleCode(userId, roleCode);
    }
}
